package cn.lg.soar.general.feign.fallback;

import cn.lg.soar.general.api.model.BizFileDTO;
import cn.lg.soar.general.api.model.FileDigestVO;
import cn.lg.soar.general.api.model.FileVO;
import cn.lg.soar.general.feign.FileApiFeign;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.web.multipart.MultipartFile;

import java.util.*;

/**
 * 文件上传接口
 * @author luguoxiang
 * 开源项目：https://gitee.com/lgx1992/lg-soar 求star！请给我star！请帮我点个star！
 */
public class FileApiFallbackFactory implements FallbackFactory<FileApiFeign> {

    protected static final Logger LOGGER = LoggerFactory.getLogger(FileApiFallbackFactory.class);

    @Override
    public FileApiFeign create(Throwable cause) {
        return new FileApiFeign() {

            @Override
            public List<FileVO> fastUpload(Long bizId, String bizType, Collection<FileDigestVO> vos) {
                LOGGER.error("fastUpload", cause);
                return Collections.emptyList();
            }

            @Override
            public List<FileVO> fastUpload(Collection<FileDigestVO> vos) {
                LOGGER.error("fastUpload", cause);
                return Collections.emptyList();
            }

            @Override
            public List<FileVO> upload(Long bizId, String bizType, Collection<MultipartFile> files) {
                LOGGER.error("upload", cause);
                return Collections.emptyList();
            }

            @Override
            public List<FileVO> upload(String bucketName, Collection<MultipartFile> files) {
                LOGGER.error("upload", cause);
                return Collections.emptyList();
            }

            @Override
            public List<FileVO> upload(Collection<MultipartFile> files) {
                LOGGER.error("upload", cause);
                return Collections.emptyList();
            }

            @Override
            public boolean saveBizFile(Long bizId, Collection<BizFileDTO> bizFiles) {
                LOGGER.error("saveBizFile", cause);
                return false;
            }

            @Override
            public Map<String, List<FileVO>> getBizFile(Long bizId, Collection<String> bizTypes) {
                LOGGER.error("getBizFile", cause);
                return Collections.emptyMap();
            }

            @Override
            public boolean removeBizFile(Long bizId, Collection<String> bizTypes) {
                LOGGER.error("removeBizFile", cause);
                return false;
            }

            @Override
            public String createTemporaryUrl(boolean anonymous, long fileId, long expire, Set<Long> userIds) {
                LOGGER.error("createTemporaryUrl", cause);
                return null;
            }

            @Override
            public String createFixedSecretUrl(long fileId) {
                LOGGER.error("createFixedSecretUrl", cause);
                return null;
            }
        };
    }
}
